package com.itcoon.cloud.framework.webmvc.config;/**
 * @author Athric Yu
 * 2024/11/11
 **/

import com.itcoon.cloud.framework.config.TemporalPatternConfig;
import com.itcoon.cloud.framework.temporal.AbstractConverter;
import com.itcoon.cloud.framework.webmvc.converter.ValueEnumConverterFactory;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.Serializable;
import java.time.temporal.Temporal;

/**
 *
 *
 * @author Athric Yu
 * 2024/11/11
 **/
public class WebConverterConfiguration implements WebMvcConfigurer {

    private final TemporalPatternConfig temporalPatternConfig;

    public WebConverterConfiguration(TemporalPatternConfig temporalPatternConfig) {
        this.temporalPatternConfig = temporalPatternConfig;
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(new ValueEnumConverterFactory<>());
        for (AbstractConverter<Serializable, Temporal> converter : temporalPatternConfig.getConverters()) {
            registry.addConverter(converter);
        }
    }
}
